<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
<title>注册登录</title>
<link href="/IndexPublic/selfhelp/css/style.css" type="text/css" rel="stylesheet">
<script src="/IndexPublic/selfhelp/js/jquery-1.7.1.min.js" type="text/javascript"></script>
</head>

<body>
	<div class="w">
		<div class="bg-box">
			<div class="title-box">
				<img src="/indexpublic/selfhelp/img/title01.png">
			</div>
			<div class="login-box">
				<form>
					<input type="number" name="usertel" placeholder="请输入手机号" class="phone-box" id="phone-box" />
					<label class="code-for" for="code-box">
						<input type="number" name="userpass" placeholder="请输入验证码" class="code-box" id="code-box" />
						<a id="jishi">获取验证码</a>
					</label>
					<a class="lgon userinfook">验证登录</a>
				</form>
			</div>
		</div>
	</div>
	<input type="hidden" name="openid" value="{$Think.cookie.user_userinfo}" />
	<script type="text/javascript">
		$(document).ready(function($) {
			/*验证手机*/
			$("a.userinfook").click(function(){
				var getopenid = $("input[name='openid']").val();
				var usertel = $("input[name='usertel']").val();
				var userpass = $("input[name='userpass']").val();
				if($.trim(usertel)==''){
					alert("请输入正确的手机号码！");
					return false;
				}
				var vget_url = "/Selfhelp/Index/getverifynote";
				var vdata = {"userpass":userpass,random:Math.random()};
				$.ajax({
					url:vget_url,
					data:vdata,
					type:"POST",
					dataType:"html",
					success:function (data){
						/*判断验证码是否正确*/
						if(data==1){
							/*手机验证通过保存数据*/
							var savetel_url = "/Selfhelp/Index/savetel";
							var teldata = {"usertel":usertel,"useropenid":getopenid,random:Math.random()};
							$.ajax({
								url:savetel_url,
								data:teldata,
								type:"POST",
								dataType:"html",
								success:function (data){
									if(data==3){
										alert("您已注册过，登录中...");
										location.href='';
										return false;
									}else if(data==2){
										alert("注册失败，请重新输入信息！");
										return false;
									}else if(data==1){
										alert("注册成功，登录中...");
										location.href='';
										return false;
									}
								}
							});
						}else{
							alert("验证不正确，请重新获取！");
							return false;
						}

					}
				});
			})

			/*发送手机验证码*/
			$("#jishi").click(function(){
				var mobile = $("input[name='usertel']").val();
				var reg = /^0?1[3|4|5|8|7][0-9]\d{8}$/;
				if (!reg.test(mobile)) {
					alert("请输入正确的手机号码！");
					$("input[name='usertel']").val(null);
					$("input[name='usertel']").focus();
					return false;
				}else{
					/*开始检测手机号是否注册过*/
					var savetel_url = "/Selfhelp/Index/telcheck";
					var teldata = {"usertel":mobile,random:Math.random()};
					$.ajax({
						url:savetel_url,
						data:teldata,
						type:"POST",
						dataType:"html",
						success:function (data){
							if(data==3){
								alert("您已注册过,直接登录中...");
								return false;
							}else{
								/*开始获取验证码并注册*/
								var send_url = "/Selfhelp/Index/verifynote";
								var senddata = {"usertel":mobile,random:Math.random()};
								$.ajax({
									url:send_url,
									data:senddata,
									type:"POST",
									dataType:"html",
									success:function (data){
									}
								});
								$("input[name='userpass']").focus();
								settime();
							}
						}
					});
				}

			})

			//倒计时
			var countdown = 30;
			function settime() {
				if (countdown == 0) {
					$("#jishi").html("获取验证码");
					countdown = 30;
					return;
				} else {
					$("#jishi").html("重新发送("+countdown+")");
					countdown--;
				}
				setTimeout(function() {
					settime()
				},1000)
			}

		});
	</script>

</body>
</html>
